#include "cab.h"

#include <string.h>
#include <string>
#include <sstream>

#include "rtdev/rtdev.h"
#include "rtbus/rtbus.h"

using rtdev::DefaultCab;

DefaultCab::DefaultCab()
{
    memset(&stat, 0, sizeof(stat));
    memset(&cmd, 0, sizeof(cmd));
}

int DefaultCab::get_hw_ver()
{
    if (scb->is_sim())
    {
        return 0xffffff;
    }
    return stat.hw_ver;
}

int DefaultCab::get_sw_ver()
{
    if (scb->is_sim())
    {
        return 0xffffff;
    }
    return stat.sw_ver;
}
std::string DefaultCab::get_version_str()
{
    if (scb->is_sim())
    {
        return std::string(scb->name()) + "_S-0.0.0-0.0.0";
    }

    // 类似ZYSCB-1.0.0-1.0.0,仿真的话就是ZYSCB_S-0.0.0-0.0.0
    std::ostringstream ss;

    // clang-format off
        ss << scb->name()                                                                                                      
           << " " << std::to_string(stat.hw_ver & 0xff0000 >> 16) << "." << std::to_string(stat.hw_ver & 0xff00 >> 8) << "." <<  std::to_string(stat.hw_ver & 0xff)
           << "-" << std::to_string(stat.sw_ver & 0xff0000 >> 16) << "." << std::to_string(stat.sw_ver & 0xff00 >> 8) << "." <<  std::to_string(stat.sw_ver & 0xff) << stat.version_status;
    // clang-format on

    return ss.str();
}
double DefaultCab::get_temperature() { return stat.pdu_temp; }
double DefaultCab::get_voltage() { return stat.cab_voltage; }
bool DefaultCab::is_poweroff_ipc() { return false; }
int DefaultCab::do_poweroff_ipc()
{
    cmd.pwr_ipc = 1;
    return 0;
}
int DefaultCab::disable_robot_commu(bool dis)
{
    cmd.dis_robot_commu = dis;
    return 0;
}
int DefaultCab::get_current_run_time() { return stat.cur_run_time; }
int DefaultCab::get_total_run_time() { return stat.total_run_time; }
